home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1042 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. From: clamage@Eng.Sun.COM (Steve Clamage)
  2. Message-ID: <4kkam3$dg8@engnews1.Eng.Sun.COM>
  3. X-Original-Date: 12 Apr 1996 01:12:35 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 12 Apr 96 07:33:34 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Ambiguity when overloading operators
  9. Organization: Sun Microsystems Inc.
  10. References: <960411233436_100754.2730_GHV68-1@CompuServe.COM>
  11. Reply-To: clamage@Eng.Sun.COM
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMW4ODuEDnX0m9pzZAQELVwF+IhLm/RdkxpBRCKZbi/G2nsAYHl2GuO+w
  14.     F9hVzl2nOVmZ/HHYWkezoV2E8DYc4B1U
  15.     =mF1V
  16.  
  17. In article 1@CompuServe.COM, Martin Aupperle <100754.2730@CompuServe.COM> write
  18. s:
  19.  
  20. >  struct  X {
  21. >    X( int );
  22. >    operator const char* () const;
  23. >    };
  24.  
  25. >  X& operator + ( const X&, const X& );
  26.  
  27. >I cannot say 
  28.  
  29. >  X x1( 5 );
  30. >  X x2 = x1+3;  // ambiguous
  31.  
  32. >Borland BC4.5 says that x1+3 is ambiguous. I know that it can
  33. >1. convert 3 to an X and call operator + ( const X&, constX& )
  34. >2. convert x1 to a const char* and do pointer arithmetics. 
  35.  
  36. Yes. Each choice involves exactly one user-defined conversion,
  37. and no user-defined conversion is preferred over any other.
  38.  
  39. The compiler is correct.
  40.  
  41. ---
  42. Steve Clamage, stephen.clamage@eng.sun.com
  43. ---
  44. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  45. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  46. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  47. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  48. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  49.